composetable: Prepare for multi character values
authorMatthias Clasen <mclasen@redhat.com>
Tue, 2 Feb 2021 04:37:05 +0000 (23:37 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 2 Feb 2021 14:02:00 +0000 (09:02 -0500)
Make it possible for gtk_compose_table_check to return
a string instead of just a single Unicode character.
Currently, we only ever return strings holding a single
character, still.

gtk/gtkcomposetable.c
gtk/gtkcomposetable.h
testsuite/gtk/composetable.c

index 033155840d1a2e4a57a76d6f89c80363e4b1e99b..ba7a201ea627950732d5579acaa86d74225f773b 100644 (file)
@@ -880,7 +880,7 @@ compare_seq (const void *key, const void *value)
  * @n_compose: number of non-zero key vals in @compose_buffer
  * @compose_finish: (out): return location for whether there may be longer matches
  * @compose_match: (out): return location for whether there is a match
- * @output_value: (out): return location for the match value
+ * @output: (out) (caller-allocates): return location for the match values
  *
  * Looks for matches for a key sequence in @table.
  *
@@ -892,14 +892,15 @@ gtk_compose_table_check (const GtkComposeTable *table,
                          int                    n_compose,
                          gboolean              *compose_finish,
                          gboolean              *compose_match,
-                         gunichar              *output_value)
+                         GString               *output)
 {
   int row_stride = table->max_seq_len + 2;
   guint16 *seq;
 
   *compose_finish = FALSE;
   *compose_match = FALSE;
-  *output_value = 0;
+
+  g_string_set_size (output, 0);
 
   /* Will never match, if the sequence in the compose buffer is longer
    * than the sequences in the table.  Further, compare_seq (key, val)
@@ -932,8 +933,11 @@ gtk_compose_table_check (const GtkComposeTable *table,
           seq[n_compose] == 0) /* complete sequence */
         {
           guint16 *next_seq;
+          gunichar value;
+
+          value = 0x10000 * seq[table->max_seq_len] + seq[table->max_seq_len + 1];
+          g_string_append_unichar (output, value);
 
-          *output_value = 0x10000 * seq[table->max_seq_len] + seq[table->max_seq_len + 1];
           *compose_match = TRUE;
 
           /* We found a tentative match. See if there are any longer
index 2b31f3678f425a37feed0e8fb8da9b265ebf2f19..88fb3c032f3623d1d285fca26544222d932a701a 100644 (file)
@@ -55,7 +55,7 @@ gboolean          gtk_compose_table_check          (const GtkComposeTable *table
                                                     int                    n_compose,
                                                     gboolean              *compose_finish,
                                                     gboolean              *compose_match,
-                                                    gunichar              *output_value);
+                                                    GString               *output);
 
 gboolean          gtk_compose_table_compact_check  (const GtkComposeTableCompact  *table,
                                                     const guint16                 *compose_buffer,
index 26659bf9f94f7b93aa3e535b658af9bcec89e35d..0d0644932f58c6148d76bced35664095cfbd06fe 100644 (file)
@@ -94,7 +94,9 @@ compose_table_match (void)
   char *file;
   guint16 buffer[8] = { 0, };
   gboolean finish, match, ret;
-  gunichar ch;
+  GString *output;
+
+  output = g_string_new ("");
 
   file = g_build_filename (g_test_get_dir (G_TEST_DIST), "compose", "match", NULL);
 
@@ -106,50 +108,53 @@ compose_table_match (void)
 
   buffer[0] = GDK_KEY_Multi_key;
   buffer[1] = 0;
-  ret = gtk_compose_table_check (table, buffer, 1, &finish, &match, &ch);
+  ret = gtk_compose_table_check (table, buffer, 1, &finish, &match, output);
   g_assert_true (ret);
   g_assert_false (finish);
   g_assert_false (match);
-  g_assert_true (ch == 0);
+  g_assert_true (output->len == 0);
 
   buffer[0] = GDK_KEY_a;
   buffer[1] = 0;
-  ret = gtk_compose_table_check (table, buffer, 1, &finish, &match, &ch);
+  ret = gtk_compose_table_check (table, buffer, 1, &finish, &match, output);
   g_assert_false (ret);
   g_assert_false (finish);
   g_assert_false (match);
-  g_assert_true (ch == 0);
+  g_assert_true (output->len == 0);
 
   buffer[0] = GDK_KEY_Multi_key;
   buffer[1] = GDK_KEY_s;
   buffer[2] = GDK_KEY_e;
-  ret = gtk_compose_table_check (table, buffer, 3, &finish, &match, &ch);
+  ret = gtk_compose_table_check (table, buffer, 3, &finish, &match, output);
   g_assert_true (ret);
   g_assert_false (finish);
   g_assert_false (match);
-  g_assert_true (ch == 0);
+  g_assert_true (output->len == 0);
 
   buffer[0] = GDK_KEY_Multi_key;
   buffer[1] = GDK_KEY_s;
   buffer[2] = GDK_KEY_e;
   buffer[3] = GDK_KEY_q;
-  ret = gtk_compose_table_check (table, buffer, 4, &finish, &match, &ch);
+  ret = gtk_compose_table_check (table, buffer, 4, &finish, &match, output);
   g_assert_true (ret);
   g_assert_false (finish);
   g_assert_true (match);
-  g_assert_true (ch == '!');
+  g_assert_cmpstr (output->str, ==, "!");
+
+  g_string_set_size (output, 0);
 
   buffer[0] = GDK_KEY_Multi_key;
   buffer[1] = GDK_KEY_s;
   buffer[2] = GDK_KEY_e;
   buffer[3] = GDK_KEY_q;
   buffer[4] = GDK_KEY_u;
-  ret = gtk_compose_table_check (table, buffer, 5, &finish, &match, &ch);
+  ret = gtk_compose_table_check (table, buffer, 5, &finish, &match, output);
   g_assert_true (ret);
   g_assert_true (finish);
   g_assert_true (match);
-  g_assert_true (ch == '?');
+  g_assert_cmpstr (output->str, ==, "?");
 
+  g_string_free (output, TRUE);
   g_free (file);
 }